import axios from 'axios';

// 获取用户信息
export const fetchUser = async () => {
  try {
    const token = sessionStorage.getItem('token');  // 从 sessionStorage 获取 token
    if (!token) {
      throw new Error('未登录，请先登录');
    }

    const response = await axios.get('http://192.168.239.53:8082/user/find', {
      headers: { Authorization: `Bearer ${token}` }  // 在请求头中传递 token
    });

    return response.data.data;  // 假设返回的数据中包含用户信息
  } catch (error) {
    console.error('Error fetching user:', error);
    throw error;
  }
};

export const updateUser = async (userData) => {
  const token = sessionStorage.getItem('token');
  const response = await axios.put('http://192.168.239.53:8082/user', userData, {
    headers: { Authorization: `Bearer ${token}` }
  });
  return response.data;
};
